import java.util.ArrayList;
import java.util.Calendar;
import controlP5.ControlP5;
import processing.core.PApplet;

//File for all static global variables
//Specifically, for the processing PApplet object
//-------------------------------------------------
//Also includes a few helper methods for categorizing sightings.

public class GLOBAL {
	
	//The processing applications
	//Call when you need to use processing functions like color()
	//		ex: GLOBAL.processing.color();
	public static PApplet processing;
	
	//The Map
	public static UnfoldingMap THE_MAP;
	
	//ControlP5 for GUI
	public static ControlP5 controlP5;
	
	//BOOLEANS for display
	public static boolean displayMap;	//True = display the map
	
	//COLORS
	//UFO Categories:
	public static int colorUnknown;		//Type #0
	public static int colorOther;		//Type #1
	public static int colorLight;		//Type #2
	public static int colorTriangle;	//Type #3
	public static int colorRect;		//Type #4
	public static int colorCircle;		//Type #5
	//Other Icons:
	public static int colorMilitary;	//Color of military base icons
	public static int colorRollover;	//Color of background of roll-over information boxes
	public static int colorPopulation;	//Color for population objects
	public static int colorAirport;		//Color of airport objects
	public static int colorWeather;		//Color of weather objects
	//Menu Colors:
	public static int colorButtonActive;
	public static int colorButtonInactive;
	//Graph Colors:
	public static int colorGraphBackground;
	public static int colorGraphAxis;
	public static int colorGraphLine;
	
	//Transparency for shapes (0-255 where 0 is fully transparent)
	public static int alpha = 195;		//For sighting data
	public static int alpha_pop = 50; 	//For population data
	
	//Width/Height adjustment for triangles
	public static int adjust = 2;
	
	//Starting and ending date selections
	public static Calendar DATE_START = Calendar.getInstance();
	public static Calendar DATE_END = Calendar.getInstance();
	
	//Selected UFO categories to be displayed.
	//Where index = type# & value at index = 1 (selected) or 0
	public static int[] selectedTypes = {0,0,0,0,0,0};
	
	public static boolean isInfoShowingS = false;
	public static boolean isInfoShowingAir = false;
	public static boolean isInfoShowingMB = false;
	public static boolean isInfoShowingWS = false;
	
	public GLOBAL(PApplet p) {
		processing = p;
		controlP5 = new ControlP5(processing);
		controlP5.setMoveable(false);
		controlP5.setAutoDraw(false);
	}
	
	//--------------------------------------------------
	//HELPER METHODS
	
	//List all Strings associated with each UFO type.
	static ArrayList<UfoType> allTypes;


	
	//Load all UFO types from file into ArrayList
	public void initTypes() {
		allTypes = new ArrayList<UfoType>();
		
		String[] typeRows = GLOBAL.processing.loadStrings("types.txt");
		String[] split;	//Used to split rows by '\t'
		
		for(int x=0; x<typeRows.length; ++x) {
			split = typeRows[x].split("\t");	//Split row by tab, '\t'
			
			if(split.length < 2) { break; }	//Invalid line
			
			allTypes.add(new UfoType(split[0], Integer.valueOf(split[1])));
			System.out.println(split[0] + ", " + Integer.valueOf(split[1]));
		}
	}
	
	//Takes "name" of sighting (eg. circle, light, ect)
	//Returns type number
	public static int getSightingType(String name) {
		name = name.toLowerCase();	//Ignore case
		
		//Parse ArrayList allTypes
		for(int x=0; x<allTypes.size(); ++x) {
			if(allTypes.get(x).matches(name))		//Check if 'name' is of the same type
				return allTypes.get(x).getNum();	//Return type number
		}
		return 0;	//Default: "unknown"
	}
	
}
